<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="zh-CN">
<head>
<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
	<meta name="viewport" content="width=device-width, initial-scale=1">
		<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
		<title>报修处理</title> <!-- Bootstrap -->
		<link href="/SmartCommunity/css/pc/bootstrap.css" rel="stylesheet">
			<link href="/SmartCommunity/css/pc/main.css" rel="stylesheet">
				<link rel="stylesheet"
					href="/SmartCommunity/css/pc/jquery-ui.min.css" />
				<link rel="stylesheet"
					href="/SmartCommunity/css/pc/jquery-ui.theme.min.css" />
</head>
<body>
	<nav class="navbar navbar-inverse navbar-fixed-top">
	<div class="container">
		<div class="navbar-header">
			<button type="button" class="navbar-toggle collapsed"
				data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"
				aria-expanded="false">
				<span class="sr-only">Toggle navigation</span> <span
					class="icon-bar"></span> <span class="icon-bar"></span> <span
					class="icon-bar"></span>
			</button>
			<a class="navbar-brand  smart" href="/SmartCommunity/views/pc/smart.html">SMART</a>
		</div>
		<!-- Collect the nav links, forms, and other content for toggling -->
		<div class="collapse navbar-collapse"
			id="bs-example-navbar-collapse-1">
			<ul class="nav navbar-nav">
			</ul>
			<form class="navbar-form navbar-right">
				<a class="btn btn-primary" id="quit">退出</a>
			</form>
		</div>
	</div>
	</nav>
	<div class="col-md-2"></div>
	<div class="maincontentinner col-md-8">
		<h4 class="widgettitle">报修情况详细审查表</h4>
		<div class="dataTables_filter">
			&nbsp;&nbsp;<label>状态</label> <select class="select_status">
				<option selected="selected" value="0">未处理</option>
				<option value="3">全部</option>
				<option value="1">处理中</option>
				<option value="2">已处理</option>
			</select>&nbsp;&nbsp; <label>时间</label> <input type="text"
				id="search_time_from" class="delivery_search_time" /> <label>—</label>
			<input type="text" id="search_time_to" class="delivery_search_time" />&nbsp;
			<input type="button" value="搜索" id="search_btn" />
		</div>
		<table class="table table-bordered responsive">
			<thead>
				<tr>
					<th class="center">姓名</th>
					<th class="center">手机</th>
					<th class="center">地址</th>
					<th class="center">题目</th>
					<th class="center">详情</th>
					<th class="center">状态</th>
					<th class="center">维修员</th>
				</tr>
			</thead>
			<tbody id="table_body">
				<tr class="template-repair" style="display: none">
					<td class="name"></td>
					<td class="phone"></td>
					<td class="room"></td>
					<td class="title"></td>
					<td class="center"><a href="javascript:void(0);" onclick="aa(this);"
						>详情</a></td>
					<td class="status center"></td>
					<td class="repair_man center"></td>
				</tr>
			</tbody>
		</table>
		<div id="page1" class="page_foot"></div>
	</div>
	
	<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog"
		aria-labelledby="exampleModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="exampleModalLabel">报修详情</h4>
				</div>
				<div class="modal-body">
					<form>
						<div class="form-group">
							<label for="detail_name" class="control-label">姓名</label> 
							<p id="detail_name">wawawaw</p>
						</div>
						<div class="form-group">
							<label for="detail_phone" class="control-label">手机号</label> 
							<p iid="detail_phone">111111111111</p>
						</div>
						<div class="form-group">
							<label for="detail_address" class="control-label">地址</label> 
							<p id="detail_address">louhsndj223</p>
						</div>
						<div class="form-group">
							<label for="detail_time" class="control-label">时间</label> 
							<p id="detail_time">2016-11-12</p>
						</div>
						<div class="form-group">
							<label for="detail_title" class="control-label">标题</label> 
							<p id="detail_title">titile</p>
						</div>
						<div class="form-group">
							<label for="detail_content" class="control-label">内容</label> 
							<p id="detail_content">contentddddddddddddddddddddddddssssssssssssssssssssssssdd</p>
						</div>
						<div class="form-group detail_pic_group" style="display:none;">
							<label id="detail_picture" class="control-label">图片</label>
							<div class="img_group"></div> 
						</div>
						<div class="form-group detail_voice_group" style="display:none;">
							<label id="detail_voice" class="control-label">音频</label> 
							<div>
							<audio controls="controls" height="100" width="100" id="audio_control">
  								<!--  <source  type="audio/mp3" />
								<embed height="100" width="100"  />-->
							</audio>
							</div>
						</div>
						
						
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" id="btn_sure_add" class="btn btn-primary"
						onclick="submitOKAdd(this)">确定</button>
				</div>
			</div>
		</div>
	</div>

	<!-- Include all compiled plugins (below), or include individual files as needed -->
	<script src="/SmartCommunity/js/pc/jquery.js"></script>
	<script src="/SmartCommunity/js/pc/init.js"></script>
	<script src="/SmartCommunity/js/pc/page.js"></script>
	<script src="/SmartCommunity/js/pc/bootstrap.js"></script>
	<script src="/SmartCommunity/js/pc/jquery.atmosphere.js"></script>
	<script language="javascript" src="/SmartCommunity/js/pc/jquery-ui.js"></script>
	<script>
		init();
		$("#search_time_from").datepicker({
			minDate : "",
			maxDate : new Date(),
			onSelect : function(dateText) {
				$("#search_time_to").datepicker("option", "minDate", dateText);
				// $("#search_time_to").datepicker("open");
			},
			altField : "#search_time_from",
			altFormat : "yy-mm-dd",
		});
		$("#search_time_to").datepicker({
			maxDate : new Date(),
			altField : "#search_time_to",
			altFormat : "yy-mm-dd"
		});

		var arr_G;
		$.ajax({
			type : "POST",
			async : false,
			url : "/SmartCommunity/pc/get_maintenance_man_info_list",
			contentType : "application/json;charset=utf-8",
			success : function(data) {
				arr_G = eval(data);
			},
			error : function() {
				alert("error");
			}
		});
		
		var page_num = 1;
		ajax_trans("/SmartCommunity/pc/get_repair_request_list?status=0&page="
				+ page_num);
		function ajax_trans(url_http) {
			$
					.ajax({
						type : "POST",
						url : url_http,
						contentType : "application/json;charset=utf-8",
						success : function(data) {
							var arr = eval("(" + data + ")");
							var pages = Math.ceil(parseInt(arr.count) / 10);
							$("#page1").unbind();
							count_pages(pages);
							arr1 = arr.content;
							for (var i = 0; i < arr1.length; i++) {
								var row = $(".template-repair").eq(0).clone();
								row.find(".name").text(arr1[i].user_name);
								row.find(".phone").text(arr1[i].telphone_num);
								addr = arr1[i].building_no + "楼"
										+ arr1[i].room_no + "房间";
								row.find(".room").text(addr);
								row.find(".title").text(arr1[i].title);
								if (arr1[i].status == 0) {
									text = "未处理";
									var temp = row.find(".repair_man");
									temp.empty();
									temp
											.append("<select class=\"select_repair_man\"/>");
									var select_man = row
											.find(".select_repair_man");
									select_man
											.append("<option selected=\"selected\" value=\"\">请选择</option>");
									for (var j = 1; j < arr_G.length; j++) {
										select_man
												.append("<option value=\'"+arr_G[j].id+"\'>"
														+ arr_G[j].name
														+ "</option>");
									}
									temp
											.append("<input type=\"button\" value=\"保存\" class=\"save_repair_man\"/>");
								} else if (arr1[i].status == 1) {
									text = "处理中";
									row.find(".repair_man").text(
											arr1[i].maintenance_man_name);
								} else {
									text = "已处理";
									row.find(".repair_man").text(
											arr1[i].maintenance_man_name);
								}
								row.find(".status").text(text);
								row.attr("id", arr1[i].id);
								if (i == 0) {
									document.getElementById("table_body").innerHTML = "";
								}
								row.css("display", "table-row");
								row.appendTo("#table_body");
							}
						},
						error : function(data) {
							alert("error");
							arr={"count":2,"content":[{"user_name":"aa","telphone_num":"11111","building_no":"11","room_no":"111","title":"aa","status":0},{"user_name":"aa","telphone_num":"11111","building_no":"11","room_no":"111","title":"aa","status":1,"maintenance_man_name":"ooo"}]};
							var pages = Math.ceil(parseInt(arr.count)/10);
							count_pages(pages);
							arr1=arr.content;
							for(var i =0; i <arr1.length; i++){
								var row = $(".template-repair").eq(0).clone();
								row.find(".name").text(arr1[i].user_name);
								row.find(".phone").text(arr1[i].telphone_num);
								addr=arr1[i].building_no+"楼"+arr1[i].room_no+"房间";
								row.find(".room").text(addr);
								row.find(".title").text(arr1[i].title);
								/*if(arr1[i].status==0){
									text="未处理";
									var temp=row.find(".repair_man");
									temp.empty();
									temp.append("<select class=\"select_repair_man\"/>");
									var select_man=row.find(".select_repair_man");
									select_man.append("<option selected=\"selected\" value=\"\">请选择</option>");
									for(var j=1;j<arr_G.length;j++)
									{
										select_man.append("<option value=\'"+arr_G[j].id+"\'>"+arr_G[j].name+"</option>");
									}
									temp.append("<input type=\"button\" value=\"保存\" class=\"save_repair_man\"/>");
								}
								else if(arr1[i].status==1){
									text="处理中";
									row.find(".repair_man").text(arr1[i].maintenance_man_name);
								}
								else{
									text="已处理";
									row.find(".repair_man").text(arr1[i].maintenance_man_name);
								}
								row.find(".status").text(text);*/
								row.attr("id",arr1[i].id);
								if(i==0){
									document.getElementById("table_body").innerHTML="";
								}
								row.css("display", "table-row");
								row.appendTo("#table_body"); 
							}
						}
					});
		}
		
		function ajax_trans_page(url_http) {
			$
					.ajax({
						type : "POST",
						url : url_http,
						contentType : "application/json;charset=utf-8",
						success : function(data) {
							var arr = eval("(" + data + ")");
							arr1 = arr.content;
							for (var i = 0; i < arr1.length; i++) {
								var row = $(".template-repair").eq(0).clone();
								row.find(".name").text(arr1[i].user_name);
								row.find(".phone").text(arr1[i].telphone_num);
								addr = arr1[i].building_no + "楼"
										+ arr1[i].room_no + "房间";
								row.find(".room").text(addr);
								row.find(".title").text(arr1[i].title);
								if (arr1[i].status == 0) {
									text = "未处理";
									var temp = row.find(".repair_man");
									temp.empty();
									temp
											.append("<select class=\"select_repair_man\"/>");
									var select_man = row
											.find(".select_repair_man");
									select_man
											.append("<option selected=\"selected\" value=\"\">请选择</option>");
									for (var j = 1; j < arr_G.length; j++) {
										select_man
												.append("<option value=\'"+arr_G[j].id+"\'>"
														+ arr_G[j].name
														+ "</option>");
									}
									temp
											.append("<input type=\"button\" value=\"保存\" class=\"save_repair_man\"/>");
								} else if (arr1[i].status == 1) {
									text = "处理中";
									row.find(".repair_man").text(
											arr1[i].maintenance_man_name);
								} else {
									text = "已处理";
									row.find(".repair_man").text(
											arr1[i].maintenance_man_name);
								}
								row.find(".status").text(text);
								row.attr("id", arr1[i].id);
								if (i == 0) {
									document.getElementById("table_body").innerHTML = "";
								}
								row.css("display", "table-row");
								row.appendTo("#table_body");
							}
						},
						error : function(data) {
							alert("error");
						}
					});
		}
		function count_pages(num) {
			var value = $(".select_status").val();
			if(value==""){
				$("#page1").createPage({
				pageCount : num,
				current : page_num,
				backFn : function(p) {
					alert(p);
					page_num = p;
					ajax_trans_page("/SmartCommunity/pc/get_repair_request_list?page=" + p + "&status=3");
				}
			});
			}else{
				$("#page1").createPage({
					
					pageCount : num,
					current : page_num,
					backFn : function(p) {
						alert(p);
						page_num = p;
						ajax_trans_page("/SmartCommunity/pc/get_repair_request_list?page=" + p + "&status="+value);
					}
				});
			}
			
		}

		$("#search_btn")
				.click(
						function() {
							var value = $(".select_status").val();
							var time_from = $("#search_time_from").val();
							var time_to = $("#search_time_to").val();
							if (value || time_from || time_to) {
								page_num=1;
								$
										.ajax({
											type : "POST",
											url : "/SmartCommunity/pc/get_repair_request_list",
											data : {
												status : value,
												page : page_num,
												dateFrom : time_from,
												dateTo : time_to
											},
											dataType : "json",
											success : function(data) {

												//alert(data);
												//var arr = eval("(" + data + ")");
												var arr=data;
												if (arr.count != 0) {
													alert(arr.count);
													page_num = 1;
													var pages = Math
															.ceil(parseInt(arr.count) / 10);
													$("#page1").unbind();
													count_pages(pages);
													arr1 = arr.content;
													for (var i = 0; i < arr1.length; i++) {
														var row = $(
																".template-repair")
																.eq(0).clone();
														row
																.find(".name")
																.text(
																		arr1[i].user_name);
														row
																.find(".phone")
																.text(
																		arr1[i].telphone_num);
														addr = arr1[i].building_no
																+ "楼"
																+ arr1[i].room_no
																+ "房间";
														row.find(".room").text(
																addr);
														row
																.find(".title")
																.text(
																		arr1[i].title);
														if (arr1[i].status == 0) {
															text = "未处理";
															var temp = row
																	.find(".repair_man");
															temp.empty();
															temp
																	.append("<select class=\"select_repair_man\"/>");
															var select_man = row
																	.find(".select_repair_man");
															select_man
																	.append("<option selected=\"selected\" value=\"\">请选择</option>");
															for (var j = 1; j < arr_G.length; j++) {
																select_man
																		.append("<option value=\'"+arr_G[j].id+"\'>"
																				+ arr_G[j].name
																				+ "</option>");
															}
															temp
																	.append("<input type=\"button\" value=\"保存\" class=\"save_repair_man\"/>");
														} else if (arr1[i].status == 1) {
															text = "处理中";
															row
																	.find(
																			".repair_man")
																	.text(
																			arr1[i].maintenance_man_name);
														} else {
															text = "已处理";
															row
																	.find(
																			".repair_man")
																	.text(
																			arr1[i].maintenance_man_name);
														}
														row.find(".status")
																.text(text);
														row.attr("id",
																arr1[i].id);
														if (i == 0) {
															document
																	.getElementById("table_body").innerHTML = "";
														}
														row.css("display",
																"table-row");
														row
																.appendTo("#table_body");
													}
												} else {
													alert("未搜索到相关内容");
													$(".template-repair").css(
															"display", "none");
												}
											},
											error : function() {
												alert("error")
											}
										});
							} else {
								alert("请输入搜索条件");
							}
						});

		function aa(e) {
			$(".img_group").empty();
			var par = $(e).parents(".template-repair");
			var id_repair = $(par).attr("id");
			$.ajax({
				type : "POST",
				url : "/SmartCommunity/pc/get_repair_request_details?id="
						+ id_repair,
				contentType : "application/json;charset=utf-8",
				success : function(data) {
					//alert(data);
					var arr = eval("(" + data + ")");
					$("#detail_name").text(arr.user_name);
					$("#detail_phone").text(arr.telphone_num);
					var addr = arr.building_no + "号楼"
					+ arr.room_no + "房间";
					$("#detail_address").text(addr);
					$("#detail_title").text(arr.title);
					$("#detail_time").text(arr.date);
					$("#detail_content").text(arr.content);
					if(arr.audio!=""){
						$(".detail_voice_group").css("display","block");
						$("#audio_control").attr("src","http://www.smartcommunitytest.cn/SmartCommunity/"+arr.audio);
						//$("#audio_control").attr("src","/SmartCommunity/views/pc/b.mp3");
					}
					//alert(arr.picture1);
					if(arr.picture1){
						$(".detail_pic_group").css("display","block");
						$(".img_group").append("<img class=\'detail_img_repair\' src=\'http://www.smartcommunitytest.cn/SmartCommunity/"+arr.picture1+"\'/>");
					}
					if(arr.picture2){
							$(".detail_pic_group").css("display","block");
							$(".img_group").append("<img class=\'detail_img_repair\' src=\'http://www.smartcommunitytest.cn/SmartCommunity/"+arr.picture2+"\'/>");
						}
					if(arr.picture3){
								$(".detail_pic_group").css("display","block");
								$(".img_group").append("<img class=\'detail_img_repair\' src=\'http://www.smartcommunitytest.cn/SmartCommunity/"+arr.picture3+"\'/>");
					}
					$('#exampleModal').modal('show');
				},
				error : function() {
					alert("error");
				}
			});
			

		}

		function submitOKAdd(e){
			$('#exampleModal').modal('hide');
			$(".detail_pic_group").css("display","none");
			$(".detail_voice_group").css("display","none");
		}
		
		$("body")
				.on(
						"click",
						".save_repair_man",
						function() {
							var par = $(this).parent().parent();
							var arr = $("td", par);
							var options1 = $(arr[6]).find("select");
							var value = options1.val();
							//var value_text=options1.find("option:selected").text();
							var id_repair = $(par).attr("id");
							if (value == "") {
								alert("请选择保修员");
							} else {
								$
										.ajax({
											type : "POST",
											url : "/SmartCommunity/pc/handle_repair_request?record_id="
													+ id_repair
													+ "&status=1&maintenance_man_id="
													+ value,
											contentType : "application/json;charset=utf-8",
											//dataType:"json",
											success : function(data) {
												if (data == "true") {
													alert("提交成功");
													ajax_trans_page("/SmartCommunity/pc/get_repair_request_list?status=0&page="

															+ page_num);
												} else {
													alert("提交失败");
												}
											},
											error : function() {
												alert("error");
											}
										});
							}
						});
	</script>
</body>

</html>